"use strict";
cc._RF.push(module, '0b457S0yLFLZLXpP2PDr32s', 'level_cardComposition_card');
// scripts/levelBundles/level_cardComposition/base/level_cardComposition_card.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var MainRoot_1 = require("../../../Game/MainRoot");
var level_cardCompositionConst_1 = require("../const/level_cardCompositionConst");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_cardComposition_card = /** @class */ (function (_super) {
    __extends(level_cardComposition_card, _super);
    function level_cardComposition_card() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.cardNode = null;
        _this.cardShowNode = null;
        _this.lightNode = null;
        _this.rainbowSpf = null;
        _this.normalSpf = null;
        _this.cardBg = null;
        _this.goldBg = null;
        /**卡牌点数 */
        _this.cardComposition = null;
        /**是否被选择 */
        _this.selectFlag = false;
        _this.showCardSpf = null;
        _this.otherCardSpf = null;
        _this.group = null;
        _this.level = null;
        _this.isJokerAni = false;
        return _this;
    }
    level_cardComposition_card.prototype.setGroup = function (group) {
        this.group = group;
    };
    level_cardComposition_card.prototype.getGroup = function () {
        return this.group;
    };
    level_cardComposition_card.prototype.initCard = function (level) {
        this.showCardSpf = null;
        this.otherCardSpf = null;
        this.stopJokerAni();
        this.selectFlag = false;
        // this.lightNode.active = false;
        this.cardNode.y = 0;
        this.lightNode.y = 0;
        this.level = level;
        this.cardShowNode.color = cc.Color.WHITE;
        this.cardBg.spriteFrame = this.normalSpf;
    };
    level_cardComposition_card.prototype.bindData = function (cardComposition, cardType) {
        this.cardComposition = cardComposition;
        this.cardType = cardType;
        this.loadCard();
    };
    /**加载卡牌 */
    level_cardComposition_card.prototype.loadCard = function () {
        var _this = this;
        console.log(this.level.getLevelInfo().levelType, "怎么个事????");
        switch (this.cardType) {
            case level_cardCompositionConst_1.level_cardCompositionCardType.universal: {
                MainRoot_1.default.LevelSystem.getOneTypeBundle(this.level.getLevelInfo().levelType).load("card/" + 13, cc.SpriteFrame, function (err, spf) {
                    if (err) {
                        console.error(err, "加载卡牌失败", err);
                        return;
                    }
                    _this.otherCardSpf = spf;
                    _this.showCardSpf = spf;
                    _this.cardShowNode.getComponent(cc.Sprite).spriteFrame = _this.otherCardSpf;
                    _this.cardBg.spriteFrame = _this.rainbowSpf;
                });
                break;
            }
            case level_cardCompositionConst_1.level_cardCompositionCardType.query: {
                MainRoot_1.default.LevelSystem.getOneTypeBundle(this.level.getLevelInfo().levelType).load("card/wenhaopai", cc.SpriteFrame, function (err, spf) {
                    if (err) {
                        console.error(err, "加载卡牌失败", err);
                        return;
                    }
                    _this.otherCardSpf = spf;
                    _this.showCardSpf = spf;
                    _this.cardShowNode.getComponent(cc.Sprite).spriteFrame = _this.otherCardSpf;
                });
                break;
            }
            case level_cardCompositionConst_1.level_cardCompositionCardType.normal: {
                MainRoot_1.default.LevelSystem.getOneTypeBundle(this.level.getLevelInfo().levelType).load("card/" + this.cardComposition, cc.SpriteFrame, function (err, spf) {
                    if (err) {
                        console.error(err, "加载卡牌失败", err);
                        return;
                    }
                    _this.cardShowNode.getComponent(cc.Sprite).spriteFrame = spf;
                    _this.cardShowNode.color = _this.level.colorMap[_this.cardComposition];
                });
                // console.log(this.cardComposition,">>>>>>>>>>>>");
                break;
            }
            case level_cardCompositionConst_1.level_cardCompositionCardType.obstacles: {
                MainRoot_1.default.LevelSystem.getOneTypeBundle(this.level.getLevelInfo().levelType).load("card/" + 15, cc.SpriteFrame, function (err, spf) {
                    if (err) {
                        console.error(err, "加载卡牌失败", err);
                        return;
                    }
                    _this.cardShowNode.getComponent(cc.Sprite).spriteFrame = spf;
                });
                break;
            }
        }
    };
    /**设置选择 */
    level_cardComposition_card.prototype.setSelect = function (selectFlag) {
        this.selectFlag = selectFlag;
        cc.Tween.stopAllByTarget(this.cardNode);
        cc.Tween.stopAllByTarget(this.lightNode);
        // this.lightNode.active = selectFlag;
        this.goldBg.active = selectFlag;
        switch (selectFlag) {
            case true: {
                cc.tween(this.lightNode).to(0.1, { y: 20 }).start();
                cc.tween(this.cardNode).to(0.1, { y: 20 }).start();
                break;
            }
            case false: {
                // this.lightNode.y = 0;
                cc.tween(this.lightNode).to(0.1, { y: 0 }).start();
                cc.tween(this.cardNode).to(0.1, { y: 0 }).start();
                break;
            }
        }
    };
    //放入组中
    level_cardComposition_card.prototype.onPushToGroup = function () {
        var _this = this;
        switch (this.cardType) {
            case level_cardCompositionConst_1.level_cardCompositionCardType.universal: {
                var curIndex = this.group.findCardIndex(this);
                var preIndex = curIndex - 1;
                var card = this.group.getCards()[preIndex];
                if (card) {
                    if (card.cardType == level_cardCompositionConst_1.level_cardCompositionCardType.universal || card.cardType == level_cardCompositionConst_1.level_cardCompositionCardType.normal) {
                        var composition = card.cardComposition;
                        this.cardComposition = composition;
                        if (composition != null) {
                            MainRoot_1.default.LevelSystem.getOneTypeBundle(this.level.getLevelInfo().levelType).load("card/" + composition, cc.SpriteFrame, function (err, spf) {
                                if (err) {
                                    console.log(err, "加载图片失败");
                                    return;
                                }
                                _this.showCardSpf = spf;
                            });
                            this.jokerAni();
                        }
                    }
                }
                break;
            }
        }
    };
    //从组中移除
    level_cardComposition_card.prototype.onSpliceToGroup = function () {
        switch (this.cardType) {
            case level_cardCompositionConst_1.level_cardCompositionCardType.universal: {
                this.stopJokerAni();
                break;
            }
        }
    };
    //开始大王的动画
    level_cardComposition_card.prototype.jokerAni = function () {
        var _this = this;
        if (this.isJokerAni) {
            return;
        }
        this.isJokerAni = true;
        var color = this.level.colorMap[this.cardComposition];
        var oneTime = 2;
        var sprite = this.cardShowNode.getComponent(cc.Sprite);
        var tween = cc.tween(this.cardShowNode).delay(oneTime).to(0.2, { opacity: 0 }).call(function () {
            MainRoot_1.default.LevelSystem.getOneTypeBundle(_this.level.getLevelInfo().levelType).load("card/" + _this.cardComposition, cc.SpriteFrame, function (err, spf) {
                if (err) {
                    console.log(err, "加载图片失败");
                    return;
                }
                _this.showCardSpf = spf;
                sprite.spriteFrame = _this.showCardSpf;
                _this.cardBg.spriteFrame = _this.normalSpf;
                _this.cardShowNode.color = color;
            });
        }).to(0.2, { opacity: 255 }).delay(oneTime).to(0.2, { opacity: 0 }).call(function () {
            sprite.spriteFrame = _this.otherCardSpf;
            _this.cardShowNode.color = cc.Color.WHITE;
            _this.cardBg.spriteFrame = _this.rainbowSpf;
        }).to(0.2, { opacity: 255 });
        cc.tween(this.cardShowNode).repeatForever(tween).start();
    };
    //停止大王的动画
    level_cardComposition_card.prototype.stopJokerAni = function () {
        this.isJokerAni = false;
        var sprite = this.cardShowNode.getComponent(cc.Sprite);
        cc.Tween.stopAllByTarget(this.cardShowNode);
        this.cardComposition = null;
        sprite.spriteFrame = this.otherCardSpf;
        this.cardShowNode.opacity = 255;
        this.cardShowNode.color = cc.Color.WHITE;
        this.cardBg.spriteFrame = this.rainbowSpf;
    };
    //卡牌翻转
    level_cardComposition_card.prototype.cardToflip = function () {
        this.cardType = level_cardCompositionConst_1.level_cardCompositionCardType.normal;
        this.loadCard();
    };
    __decorate([
        property({ type: cc.Node, tooltip: "卡牌节点" })
    ], level_cardComposition_card.prototype, "cardNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "卡牌显示节点" })
    ], level_cardComposition_card.prototype, "cardShowNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "高亮显示节点" })
    ], level_cardComposition_card.prototype, "lightNode", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "彩虹图片" })
    ], level_cardComposition_card.prototype, "rainbowSpf", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "普通图片" })
    ], level_cardComposition_card.prototype, "normalSpf", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "牌的背景" })
    ], level_cardComposition_card.prototype, "cardBg", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "金色背景" })
    ], level_cardComposition_card.prototype, "goldBg", void 0);
    level_cardComposition_card = __decorate([
        ccclass
    ], level_cardComposition_card);
    return level_cardComposition_card;
}(cc.Component));
exports.default = level_cardComposition_card;

cc._RF.pop();